package com.gujia.designpattern.factory;

import com.gujia.designpattern.factory.impl.LeftHair;
import com.gujia.designpattern.factory.impl.RightHair;

/**
 * 发型工厂
 */
public class HairFactory {

    public HairInterface getHair(String key){
        if("left".equals(key)){
            return new LeftHair();
        }else if("right".equals(key)){
            return new RightHair();
        }else{
            return null;
        }

    }

    public HairInterface getHairByClass(String className){
        HairInterface hair = null;
        try {
            hair = (HairInterface)Class.forName(className).newInstance();

            return hair;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return hair;
    }

    public HairInterface getHairByClass(Class<? extends HairInterface> clazz){
        HairInterface hair = null;
        try {
            hair = (HairInterface)Class.forName(clazz.getName()).newInstance();

            return hair;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return hair;
    }




}
